package study.java.jdk.jdk8._1_stream.collectors.to_collection;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

@Slf4j
public class toCollection_Test {

    private List<String> src = Arrays.asList("123", "456", "789", "123");

    /**
     * @param collectionFactory -Supplier: Collection构造器
     */
    @Test
    public void test1() {
        List<String> dest = src.stream()
                .collect(Collectors.toCollection(LinkedList::new));
        log.info("{}", dest);

        //
        Collectors.toCollection(LinkedList::new);
        Collectors.toCollection(() -> new LinkedList<>());
        //
        src.stream()
                .collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(e -> e))));
    }

    @Test
    public void test2() {
        Set<String> dest = src.stream()
                .collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(e -> e))));
        log.info("{}", dest.getClass().getSimpleName());
        log.info("{}", dest);
    }
}
